package com.qifan.alb2b.action.back;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qifan.alb2b.domain.AdminInfoDomain;
import com.qifan.alb2b.service.AdminInfoService;
import com.qifan.alb2b.util.Constants;
import com.qifan.alb2b.util.Stringer;

@Controller
@RequestMapping("/admin")
public class BackLoginController{
	private AdminInfoService adminInfoService;

	public void setAdminInfoService(AdminInfoService adminInfoService) {
		this.adminInfoService = adminInfoService;
	}
	@RequestMapping("/login.adm")
	@ResponseBody
	public Map<String, Object> login(HttpServletRequest request,@RequestParam("adminName") String adminName, @RequestParam("adminPwd") String adminPwd) {
		Map<String, Object> map=new HashMap<String, Object>();
		AdminInfoDomain admin =adminInfoService.getAdmin(adminName,Stringer.md5(adminPwd).substring(0,30));
		if(admin!=null){
			request.getSession().setAttribute(Constants.SESSION_ADMIN, admin);
			map.put("success", true);		
		}
		return map;
	}
	
	@RequestMapping("/logout.adm")
	public String logout(HttpSession session){
		session.invalidate();
		return "pages/back/login";
	}
	
	
	
}
